home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / inventor / www / workarounds / HiddenChildren.C < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  2.9 KB  |  88 lines

  1. //
  2. // Inventor 2.0 bug fixes that affect correctness of programs that work with
  3. // Nodekits and Hidden Children.
  4. // 
  5. // The code in this file fixes problems in the following routines:
  6. // SoPath::getLength()
  7. // SoPickedPoint::getMatrix()
  8. // 
  9. // To get the fixes, compile this file into a .o and then link
  10. // the .o before -lInventor_s.  The linker may give a warning.
  11. // This is normal and expected.
  12. //
  13. // SoPath::getLength() bug:
  14. //     SoPath::getLength and SoPath::getTail can return the wrong answer if the 
  15. //     path contains hidden children. This happens if nodes are appended 
  16. //     between subsequent calls to getLength or getTail. The returned value can 
  17. //     be too large or too far down the path. This error should never cause a 
  18. //     core dump because in the worst case returned length will be the full 
  19. //     path length and the returned tail will be the tail of the full path.
  20. //     Note that only getLength() needs to be fixed. getTail() will be fixed
  21. //     automatically, since its error occurs only because it gets the wrong 
  22. //     answer from getLength.
  23. //
  24. // SoPickedPoint::getMatrix bug:
  25. //     SoPickedPoint::getMatrix does a check to see if the given node is the 
  26. //     tail of the picked path.   If it is the tail, it applies an 
  27. //     SoGetMatrixAction to the entire path. If not, it builds a path from the 
  28. //     head down to the given node.
  29. //
  30. //     The method should cast the path to an SoFullPath when looking at the
  31. //     tail, otherwise if there is a nodekit along the path it will be 
  32. //     incorrectly applying the action to the full path.
  33. //
  34. #include <Inventor/SoPath.h>
  35. #include <Inventor/SoPickedPoint.h>
  36. #include <Inventor/actions/SoGetMatrixAction.h>
  37. #include <Inventor/nodes/SoGroup.h>
  38.  
  39. int
  40. SoPath::getLength() const
  41. {
  42.     // Cast const away...
  43.     SoPath *This = (SoPath *)this;
  44.  
  45.     // If we aren't sure how many are public, figure it out:
  46.     if (numPublic == -1) {
  47.  
  48.     int lastPublicIndex = 0;
  49.     if (minNumPublic > 1)
  50.         lastPublicIndex = minNumPublic - 1;
  51.  
  52.     // Last test is for the second to last node.
  53.     // If it passes, then lastPublicIndex will be incremented to be the
  54.     // final node, which we don't need to test.
  55.  
  56.     for (  ; lastPublicIndex < (getFullLength() - 1) ; lastPublicIndex++) {
  57.         // Children of this node will be private, so stop.
  58.         if ( ! nodes[lastPublicIndex]->isOfType(SoGroup::getClassTypeId()))
  59.         break;
  60.     }
  61.     This->numPublic = This->minNumPublic = lastPublicIndex + 1;
  62.     }
  63.     return numPublic;
  64. }
  65.  
  66. void
  67. SoPickedPoint::getMatrix(SoGetMatrixAction *gma, const SoNode *node) const
  68. {
  69.     SoPath *xfPath;
  70.  
  71.     // Construct a path from the root down to this node. Use the given
  72.     // path if it's the same
  73.     if (node == NULL || node == ((SoFullPath *)path)->getTail())
  74.     xfPath = path;
  75.  
  76.     else {
  77.     int     index = getNodeIndex(node);
  78.     xfPath = path->copy(0, index + 1);
  79.     xfPath->ref();
  80.     }
  81.  
  82.     gma->apply(xfPath);
  83.  
  84.     if (xfPath != path)
  85.     xfPath->unref();
  86. }
  87.  
  88.